import React from 'react';
import { Redirect } from 'umi';
import { stringify } from 'querystring';

const SecurityLayout = props => {
  const { children } = props; // You can replace it to your authentication rule (such as check token exists)
  // // 你可以把它替换成你自己的登录认证规则（比如判断 token 是否存在）

  // ( 为了单点登录，暂时注释)
  // const isLogin = localStorage.getItem('authorization');
  // const queryString = stringify({
  //   redirect: window.location.href,
  // });

  // const { pathname, search } = window.location;
  // const redirect = encodeURIComponent(`${pathname}${search}`);

  // if (!isLogin && pathname !== '/user/login') {
  //   localStorage.clear();
  //   return <Redirect to={`/user/login?${redirect}`} />;
  // }

  return children;
};

export default SecurityLayout;
